package com.iotek.ssm.controller;

import com.iotek.ssm.pojo.CustomQueryVo;
import com.iotek.ssm.pojo.SalarySheet;
import com.iotek.ssm.pojo.SalarySheetQueryVo;
import com.iotek.ssm.service.SalarySheetService;
import com.iotek.ssm.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/salary")
public class SalarySheetController {

    @Autowired
    private SalarySheetService salarySheetService;

    @Autowired
    private Util util;

    //单数据插入
    @RequestMapping("/addSalary")
    public int addSalary(SalarySheet salarySheet) {
        try {
            salarySheetService.addSalarySheet(salarySheet);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    //多数据批量插入
    @RequestMapping("/addSalaryList")
    public String addSalary(Model model, SalarySheetQueryVo salarySheetQueryVo) {
        List<SalarySheet> salarySheets = salarySheetQueryVo.getSalaryList();
        System.out.println("*******************----------------------" + salarySheets);
        try {
            salarySheetService.addSalaryList(salarySheets);
            util.setJumpDetails(model, "添加成功！", "进入管理主页", "../admin/managePageJump", 1);
        } catch (Exception e) {
            e.printStackTrace();
            util.setJumpDetails(model, "添加失败！", "进入管理主页", "../admin/managePageJump", 1);
        }
        return "jumpPage";
    }

    @RequestMapping("/findSalaryList")
    @ResponseBody
    public List<SalarySheet> findSalaryList(CustomQueryVo customQueryVo) {
        List<SalarySheet> salarySheets = null;
        try {
            salarySheets = salarySheetService.findSalarySheet(customQueryVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return salarySheets;
    }
}
